var ntko;//控件对象
var CLOSEVENT = false;
//初始化去打开文档
function  init(cmd){
	ntko = document.getElementById("TANGER_OCX");
	if(window.navigator.platform=="Win64"){
		//alert("平台版文档控件，请使用32位浏览器如IE");
		//TANGER_OCX_OBJ.AddDocTypePlugin(".tif","tif.NtkoDocument","4.0.1.0","officecontrol/ntkooledocallx64.cab",51,true);
		ntko.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.2.0","officecontrol/ntkooledocallx64.cab",51,true);

	}else{
			ntko.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.2.0","officecontrol/ntkooledocall.cab",51,true);//版增加对于PDF文件的支持
			//TANGER_OCX_OBJ.AddDocTypePlugin(".tif","tif.NtkoDocument","4.0.1.0","officecontrol/ntkooledocallx64.cab",51,true);
	}
  ntko.TitleBar=false;
  //ntko.ToolBars = false;
  ntko.Menubar = false
  ntko.Caption  = false;
  ntko.OpenFromURL('http://58.240.123.98:8060/lawyarCaseFiles/'+cmd);
  var o = document.getElementById("btn");
  var h = o.clientHeight||o.offsetHeight;
  ntko.style.height=($(window).height() - h-20) +'px'
}
function saveFiles(){
  var url = window.location.href;
  var str = url.split('?');
  var str2 = str[1].split('&');
  var id=str2[1];
  var names='';
  if(str2[0].indexOf('/')){
    names = str2[0].split('/')[str2[0].split('/').length-1];
  }else if(str2[0].indexOf('\\')){
    names = str2[0].split('\\')[str2[0].split('\\').length-1];
  }
  //var inf  = ntko.SaveToURL('http://localhost:9795/file/upload','divBody','','测试文档.doc');
  var inf  = ntko.SaveToURL('http://58.240.123.98:8060/lawyarCaseUpFile/','divBody','',names);
  var info = JSON.parse(inf);
  if(info.code==0){
    var fileUrl = info.data.address.replace(/\\/g,'//');
    console.log(url);
    $.ajax({
      //请求方式
      type : "POST",
      //请求地址
      url : "http://58.240.123.98:8060/lawyarCase/system/caseFile/addOrEdit2",
      //数据，json字符串
      data : {
        ids : id,
        fileUrls:fileUrl,
        tabNameSuffix:str2[2],
        oldName:str2[0]
      },
      //请求成功
      success : function(result) {
        alert('保存成功')
        window.opener=null;
        window.open('','_self');
        window.close();
      },
      //请求失败，包含具体的错误信息
      error : function(e){
        alert('保存失败')
        console.log(e.status);
        console.log(e.responseText);
      }
    });
  }else{
    alert('保存文件失败')
  }
}

